package com.chima.dao;

import java.util.List;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.chima.domain.Department;
import com.chima.domain.DetailJob;
import com.chima.domain.TastJob;
public class DetailJobDao extends HibernateDaoSupport{
	
	
	public DetailJob findById(int id) {
	    Session session=this.getSession();
	    DetailJob j=(DetailJob) session.createQuery(" from DetailJob  where id=?").setParameter(0,id).uniqueResult();
		super.releaseSession(session);
		return j;
	}
	
	public  List<DetailJob>   findByJobId(int id) {
	    Session session=this.getSession();
	    List<DetailJob> j= session.createQuery(" from DetailJob  where tastJob.id=?").setParameter(0,id).list();
		super.releaseSession(session);
		return j;
	}
     public void addDetailJob(DetailJob detailJob){
    	   this.getHibernateTemplate().save(detailJob);
    	 
     }
     public void updateDetailJob(DetailJob detailJob){
  	   this.getHibernateTemplate().update(detailJob);
  	 
   }
     public void deleteDetailJob(int id){
  	   this.getHibernateTemplate().delete(this.getHibernateTemplate().load(DetailJob.class, id));
  	 
   }
     public  List<DetailJob>findByEmpAndState(int emp, String state) {
 	    Session session=this.getSession();
 	    List<DetailJob> j= session.createQuery(" from DetailJob  where employee.id=? and state <? ").setParameter(0,emp).setParameter(1, state).list();
 		super.releaseSession(session);
 		return j;
 	}
     public TastJob findTastJobByJobId(int Jobid) {
 		
    	 Session session=this.getSession();
    	 TastJob t= (TastJob) session.createQuery(" from TastJob  where id=? ").setParameter(0,Jobid).uniqueResult();
  		 super.releaseSession(session);
  		 return t;
 	}
 	public void deletDetailJobByemp(int empid) {
		
// 		String hql="DELETE * FROM DetailJob  where employee.id=?";
//		Session session=this.getSession();
//		session.createQuery(hql).setParameter(0,empid ).executeUpdate();
//		super.releaseSession(session);
		Session session=this.getSession();
		 String sql1=" delete  from t_detailjob where empID=?";
		 session.createSQLQuery(sql1).setParameter(0, empid).executeUpdate();
		 super.releaseSession(session);
 	}
}
